//
//  footview.m
//  Feeds2
//
//  Created by cos on 2020/11/25.
//  Copyright © 2020 cos. All rights reserved.
//

#import "footview.h"

@implementation footview
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (footview *)refreshFooterView
{
    footview *refreshFooterView = [[self alloc] init];
    refreshFooterView.frame = CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width, 35);
    
    return refreshFooterView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self)
    {
        self.opaque = YES;
    }
    
    return self;
}

#pragma mark - 设置子控件
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    /* 提示文字 */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    
    // 位置位置和尺寸
    
    // 设置文字样式
    label.text = @"正在加载更多数据";
    label.font = [UIFont systemFontOfSize:17];
    label.textAlignment = NSTextAlignmentCenter;
    
    // 获取文字宽度
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = label.font;
    CGFloat textWidth = [label.text sizeWithAttributes:attr].width;
    
    [self addSubview:label];
    
    /* 菊花 */
    UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    
//    activity.width = label.height;
//    activity.height = label.height;
//    activity.y = 0;
//    activity.x = (label.width + textWidth) * 0.5;
    activity.frame = CGRectMake((label.frame.size.width+textWidth)*0.5, 0, label.frame.size.height, label.frame.size.height);
    
    [activity startAnimating];
    
    [self addSubview:activity];
}

@end
